package com.cucn.mms.common.controller;

import com.cucn.mms.common.service.Interface.MediaManageService;
import com.cucn.mms.domain.MediaManageDO;
import com.cucn.mms.domain.MmsMediaInfo;
import com.cucn.mms.exception.MMSServiceException;

import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 视频管理请求处理
 *
 * @author Ken
 */
@Controller
@RequestMapping(value = "/**/mediaManage")
@Slf4j
public class MediaManageController
{

	@Autowired
	private MediaManageService mediaManageService;

	/**
	 * 可指定媒资信息查询
	 *
	 * @param keyword
	 *            查询关键字
	 * @param searchType
	 *            查询类型 //
	 * @param offset
	 *            分页偏移值
	 * @param limit
	 *            分页大小
	 * @return 结果的一个Map，其中： key为 rows 的代表记录数据；key 为 total 代表结果记录的数量
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "getMediaList", method = RequestMethod.GET)
	public @ResponseBody Map<String, Object> getMediaList( String keyword,
														   String searchType,  int offset,
														   int limit) throws MMSServiceException {
		Map<String,Object> map = mediaManageService.selectMediaByType(keyword,searchType,offset,limit);
		return map;
	}

	/**
	 *  删除媒体记录
	 * @param mediaId
	 * @return
	 * @throws MMSServiceException
	 */
	@RequestMapping(value = "deleteMediaRecord", method = RequestMethod.GET)
	public @ResponseBody Map<String, Object> deleteMediaRecord(String mediaId) throws MMSServiceException {
		return mediaManageService.deleteMediaById(mediaId);
	}

	@RequestMapping(value = "updateMediaRecord", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> updateMediaRecord(@RequestBody Map<String, Object> params)
			throws MMSServiceException {
		return mediaManageService.updateMedia(params);
	}

	@RequestMapping(value = "addMedia", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> addMedia(@RequestParam("mediaName") String mediaName,
													  @RequestParam("mediaCategory") Integer mediaCategory,
													  @RequestParam("mediaGrade") Integer mediaGrade, @RequestParam("mediaUrl") String mediaUrl)
			throws MMSServiceException {
		return mediaManageService.addMedia(mediaName,mediaCategory,mediaGrade,mediaUrl);
	}

	/**
	 *  ljcys
	 * @return
	 */
	@GetMapping("/ljcys")
	public @ResponseBody Map<String, Object> cys() {
		return (Map<String, Object>) MapUtils.EMPTY_MAP;
	}
}
